﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BeatlesBlog.SimConnect;
using FA.Library.Sim.Aircraft;
using FA.Library.Util;
using System.ComponentModel;

namespace FA.Plugins.FSXPlugin.Sim.Aircraft
{
    [DataStruct()]
    public class FSXAircraftEngine : BaseCloneable, AircraftEngine
    {
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Number of engines.
        /// </summary>
        [DataItem("NUMBER OF ENGINES", 32)]
        public int NumEngines
        {
            get { return _numEngines; }
            private set
            {
                if (_numEngines != value)
                {
                    _numEngines = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("NumEngines"));
                }
            }
        }
        private int _numEngines;

        /// <summary>
        /// Selected engines (combination of bit flags).
        /// </summary>
        [DataItem("ENGINE CONTROL SELECT", 32)]
        public int SelectedEnginesMask
        {
            get { return _selectedEngines; }
            set
            {
                if (_selectedEngines != value)
                {
                    _selectedEngines = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("SelectedEnginesMask"));
                }
            }
        }
        private int _selectedEngines;

        /// <summary>
        /// Engine type enumeration.
        /// </summary>
        [DataItem("ENGINE TYPE", 32)]
        public int EngineTypeEnum
        {
            get { return _engineType; }
            private set
            {
                if (_engineType != value)
                {
                    _engineType = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("EngineTypeEnum"));
                }
            }
        }
        private int _engineType;

        /// <summary>
        /// Throttle lever.
        /// </summary>
        [DataItem("GENERAL ENG THROTTLE LEVER POSITION:1", "percent")]
        public int ThrottleLeverPosition
        {
            get { return _throttleLeverPos; }
            set
            {
                if (_throttleLeverPos != value)
                {
                    _throttleLeverPos = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("ThrottleLeverPosition"));
                }
            }
        }
        private int _throttleLeverPos;

        /// <summary>
        /// Mixture lever.
        /// </summary>
        [DataItem("GENERAL ENG MIXTURE LEVER POSITION:1", "percent")]
        public int MixtureLeverPosition
        {
            get { return _mixtureLeverPos; }
            set
            {
                if (_mixtureLeverPos != value)
                {
                    _mixtureLeverPos = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("MixtureLeverPosition"));
                }
            }
        }
        private int _mixtureLeverPos;

        /// <summary>
        /// Propeller lever.
        /// </summary>
        [DataItem("GENERAL ENG PROPELLER LEVER POSITION:1", "percent")]
        public int PropellerLevelPosition
        {
            get { return _propellerLeverPos; }
            set
            {
                if (_propellerLeverPos != value)
                {
                    _propellerLeverPos = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("PropellerLevelPosition"));
                }
            }
        }
        private int _propellerLeverPos;

        /// <summary>
        /// Percent throttle defining lower limit (negative for reverse thrust equipped airplanes).
        /// </summary>
        [DataItem("THROTTLE LOWER LIMIT", "percent")]
        public int ThrottleLowerLimit
        {
            get { return _throttleLowerLimit; }
            private set
            {
                if (_throttleLowerLimit != value)
                {
                    _throttleLowerLimit = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("ThrottleLowerLimit"));
                }
            }
        }
        private int _throttleLowerLimit;

        /// <summary>
        /// Engine 1 RPM.
        /// </summary>
        [DataItem("GENERAL ENG RPM:1", "rpm")]
        public float Engine1RPM
        {
            get { return _engine1RPM; }
            private set
            {
                if (_engine1RPM != value)
                {
                    _engine1RPM = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("Engine1RPM"));
                }
            }
        }
        private float _engine1RPM;

        /// <summary>
        /// Engine 2 RPM.
        /// </summary>
        [DataItem("GENERAL ENG RPM:2", "rpm")]
        public float Engine2RPM
        {
            get { return _engine2RPM; }
            private set
            {
                if (_engine2RPM != value)
                {
                    _engine2RPM = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("Engine2RPM"));
                }
            }
        }
        private float _engine2RPM;

        /// <summary>
        /// Engine 1 failed flag.
        /// </summary>
        [DataItem("GENERAL ENG FAILED:1", "bool")]
        public bool Engine1FailFlag
        {
            get { return _engine1Failed; }
            private set
            {
                if (_engine1Failed != value)
                {
                    _engine1Failed = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("Engine1FailFlag"));
                }
            }
        }
        private bool _engine1Failed;

        /// <summary>
        /// Engine 2 failed flag.
        /// </summary>
        [DataItem("GENERAL ENG FAILED:2", "bool")]
        public bool Engine2FailFlag
        {
            get { return _engine2Failed; }
            private set
            {
                if (_engine2Failed != value)
                {
                    _engine2Failed = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("Engine2FailFlag"));
                }
            }
        }
        private bool _engine2Failed;

        /// <summary>
        /// Engine 1 on fire flag.
        /// </summary>
        [DataItem("ENG ON FIRE:1", "bool")]
        public bool Engine1OnFireFlag
        {
            get { return _engine1OnFire; }
            set
            {
                if (_engine1OnFire != value)
                {
                    _engine1OnFire = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("Engine1OnFireFlag"));
                }
            }
        }
        private bool _engine1OnFire;

        /// <summary>
        /// Engine 2 on fire flag.
        /// </summary>
        [DataItem("ENG ON FIRE:2", "bool")]
        public bool Engine2OnFireFlag
        {
            get { return _engine2OnFire; }
            set
            {
                if (_engine2OnFire != value)
                {
                    _engine2OnFire = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("Engine2OnFireFlag"));
                }
            }
        }
        private bool _engine2OnFire;

        /// <summary>
        /// Combustion flag.
        /// </summary>
        [DataItem("GENERAL ENG COMBUSTION:1", "bool")]
        public bool CombustionFlag
        {
            get { return _combustion; }
            set
            {
                if (_combustion != value)
                {
                    _combustion = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("CombustionFlag"));
                }
            }
        }
        private bool _combustion;

        /// <summary>
        /// Aircraft master ignition switch (grounds all engines’ magnetos).
        /// </summary>
        [DataItem("MASTER IGNITION SWITCH", "bool")]
        public bool MasterIgnitionSwitch
        {
            get { return _masterIgnition; }
            private set
            {
                if (_masterIgnition != value)
                {
                    _masterIgnition = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("MasterIgnitionSwitch"));
                }
            }
        }
        private bool _masterIgnition;

        /// <summary>
        /// Master alternator (generator) switch.
        /// </summary>
        [DataItem("GENERAL ENG MASTER ALTERNATOR:1", "bool")]
        public bool MasterAlternatorSwitch
        {
            get { return _masterAlternator; }
            private set
            {
                if (_masterAlternator != value)
                {
                    _masterAlternator = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("MasterAlternatorSwitch"));
                }
            }
        }
        private bool _masterAlternator;

        /// <summary>
        /// Engine 1 alternator (generator) on/off.
        /// </summary>
        [DataItem("GENERAL ENG GENERATOR ACTIVE:1", "bool")]
        public bool Engine1Alternator
        {
            get { return _engine1Alternator; }
            set
            {
                if (_engine1Alternator != value)
                {
                    _engine1Alternator = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("Engine1Alternator"));
                }
            }
        }
        private bool _engine1Alternator;

        /// <summary>
        /// Engine 2 alternator (generator) on/off.
        /// </summary>
        [DataItem("GENERAL ENG GENERATOR ACTIVE:2", "bool")]
        public bool Engine2Alternator
        {
            get { return _engine2Alternator; }
            set
            {
                if (_engine2Alternator != value)
                {
                    _engine2Alternator = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("Engine2Alternator"));
                }
            }
        }
        private bool _engine2Alternator;
    }
}